package doorwifi.wd.patientsation.peripheral.mainapp.utils;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by 王松 on 2016/8/10.
 */
public class MyItemDecoration extends RecyclerView.ItemDecoration {
    //表示两个item之间的间距
    private int space;

    public MyItemDecoration(int space) {
        this.space = space;
    }

    //获取每一个item上下左右四个方向的偏移量
    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        //第一个参数表示每一个item所处的矩形
        outRect.bottom = space;
        outRect.left = space;
        outRect.right = space;
        if (parent.getChildLayoutPosition(view) == 0 || parent.getChildLayoutPosition(view) == 1 || parent.getChildLayoutPosition(view) == 2) {
            outRect.top = space;
        }
        if (parent.getChildLayoutPosition(view) % 3 != 0) {
            outRect.left = 0;
        }
    }

    //绘制分割线，该方法所绘制出来的分割线和item在同一平面上
    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDraw(c, parent, state);
    }

    //绘制分割线，该方法所绘制出来的分割线和item不在同一平面上
    @Override
    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDrawOver(c, parent, state);
    }
}
